﻿@using NewLife.Web;
@using XCode;
@using NewLife.Cube.Charts;
@using NewLife;
@using XCode.Configuration;
@{
    //Layout = NewLife.Cube.Setting.Current.Layout;

    var fact = ViewBag.Factory as IEntityFactory;
    var page = ViewBag.Page as Pager;
    var set = ViewBag.PageSetting as PageSetting ?? PageSetting.Global;

    var charts = ViewBag.Charts as ECharts[];
    var charts2 = ViewBag.Charts2 as ECharts[];

    var fields = ViewBag.Fields as FieldCollection;
    var ukey = fact.Unique;
}

@section css{
    <style>
        .layui-fluid {
            padding: 10px;
        }
    </style>
}

    <div class="layui-fluid" id="mainpage">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-panel">
                    <div class="layui-card-body">
                        <table lay-filter="parse-table-demo">
                            <thead>
                                <tr>
                                    @foreach (var item in fields)
                                {
                                    if (item.Type == typeof(DateTime))
                                    {
                                        var width = item.Name.EndsWithIgnoreCase("Date") ? 96 : 150;
                                        <th lay-data="{field:'@item.Name',minWidth:@width,title:'@item.Description'}">@item.DisplayName</th>
                                    }
                                    else
                                    {
                                        <th lay-data="{field:'@item.Name',title:'@item.Description'}">@item.DisplayName</th>
                                    }
                                }

                                @if (this.Has(PermissionFlags.Detail, PermissionFlags.Update, PermissionFlags.Delete))
                                {
                                    <th lay-data="{toolbar:'#barOpt',minWidth:120,fixed:'right',align:'center'}">操作</th>
                                }
                            </tr>
                        </thead>
                        <tbody>
                            @foreach (var entity in Model)
                            {
                                <tr>
                                    @foreach (var item in fields)
                                    {
                                        var df = item as ListField;
                                        var link = "";
                                        if (df != null && df.DataVisible != null && !df.DataVisible(entity))
                                        {
                                            <td></td>
                                        }
                                        else if (df != null && (link = df.GetLink(entity)) != null)
                                        {
                                            <td class="text-center">@Html.Raw(link)</td>
                                        }
                                        else
                                        {
                                            @await Html.PartialAsync("_List_Data_Item", new ValueTuple<IEntity, DataField>(entity, item))
                                        }
                                    }
                                </tr>
                            }
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

@section scripts{
    <script>
        layui.use('table', function() {
            var table = layui.table
            $ = layui.$;

            table.init('parse-table-demo', { //转化静态表格
                page: true,
                limit: 20,
                limits: [20, 50, 100],
                size: "sm",
                even: true,
                toolbar: "#toolbarDemo"
            });
        });
    </script>

    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
            <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
            <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
        </div>
    </script>

    @* 设置行操作按钮*@
    @if (this.Has(PermissionFlags.Detail, PermissionFlags.Update, PermissionFlags.Delete))
    {
        @foreach (var entity in Model)
        {
            @await Html.PartialAsync("_List_Data_Action", (Object)entity)
            break;
        }
    }
}